class ControlGroupsController < ApplicationController
  # GET /control_groups
  # GET /control_groups.json
  def index
    @control_groups = ControlGroup.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @control_groups }
    end
  end

  # GET /control_groups/1
  # GET /control_groups/1.json
  def show
    @control_group = ControlGroup.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @control_group }
    end
  end

  # GET /control_groups/new
  # GET /control_groups/new.json
  def new
    @control_group = ControlGroup.new
    @candiates = Candidate.all
    @orgs = Org.all
    @questions = Question.all

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @control_group }
    end
  end

  # GET /control_groups/1/edit
  def edit
    @control_group = ControlGroup.find(params[:id])
    @candiates = @control_group.candidates
    @orgs = @control_group.orgs
    @questions = @control_group.questions
  end

  # POST /control_groups
  # POST /control_groups.json
  def create
    @control_group = ControlGroup.new(params[:control_group])

    respond_to do |format|
      if @control_group.save
        format.html { redirect_to @control_group, notice: 'Control group was successfully created.' }
        format.json { render json: @control_group, status: :created, location: @control_group }
      else
        format.html { render action: "new" }
        format.json { render json: @control_group.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /control_groups/1
  # PUT /control_groups/1.json
  def update
    @control_group = ControlGroup.find(params[:id])

    respond_to do |format|
      if @control_group.update_attributes(params[:control_group])
        format.html { redirect_to @control_group, notice: 'Control group was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @control_group.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /control_groups/1
  # DELETE /control_groups/1.json
  def destroy
    @control_group = ControlGroup.find(params[:id])
    @control_group.destroy

    respond_to do |format|
      format.html { redirect_to control_groups_url }
      format.json { head :no_content }
    end
  end
end
